
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;

namespace Swaf
{
	/// <summary>
	/// Summary description for NameAddress.
	/// </summary>
	public class NameAddress
	{
		protected static char addressSeperator = '.';
		
		public static bool isSingleAddress(string name) {
			if(name == null) return true;
			return name.IndexOf(addressSeperator) == -1?true:false;
		}
		public static string getFirstAddress(string name) {
			if(name == null) return null;
			int pos = name.IndexOf(addressSeperator);
			if(pos != -1)
				return name.Substring(0, pos);
			else
				return name;
		}
		
		public static string getRemainingAddress(string name) {
			int pos = name.IndexOf(addressSeperator);
			if(pos != -1)
				return name.Substring(pos +1);
			else 
				return null;
		}

		public static string getAllButLast(string name) {
			int pos = name.LastIndexOf(addressSeperator);
			if(pos != -1)
				return name.Substring(0, pos);
			else
				return null;
		}

		public static string getLastAddress(string name) {
			int pos = name.LastIndexOf(addressSeperator);
			if(pos != -1)
				return name.Substring(pos +1);
			else
				return name;
		}
	}
}
